// SPDX-License-Identifier: Apache-2.0
//
// Copyright © 2017 Trust Wallet.

#include "Ethereum/ContractCall.h"
#include "HexCoding.h"

#include <fstream>
#include <gtest/gtest.h>

extern std::string TESTS_ROOT;

namespace TW::Ethereum::ABI::tests {

static nlohmann::json load_json(const std::string& path) {
    std::ifstream stream(path);
    nlohmann::json json;
    stream >> json;
    return json;
}

static std::string load_json_str(const std::string& path) {
    std::ifstream stream(path);
    std::string json((std::istreambuf_iterator<char>(stream)),
                    std::istreambuf_iterator<char>());
    return json;
}

TEST(ContractCall, Approval) {
    auto path = TESTS_ROOT + "/chains/Ethereum/Data/erc20.json";
    auto abi = load_json_str(path);
    auto call = parse_hex("095ea7b30000000000000000000000005aaeb6053f3e94c9b9a09f33669435e7ef1beaed"
                          "0000000000000000000000000000000000000000000000000000000000000001");
    auto decoded = decodeCall(call, abi);

    auto expected =
        R"|({"function":"approve(address,uint256)","inputs":[{"name":"_spender","type":"address","value":"0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed"},{"name":"_value","type":"uint256","value":"1"}]})|";

    EXPECT_EQ(decoded.value(), expected);
}

TEST(ContractCall, UniswapSwapTokens) {
    auto path = TESTS_ROOT + "/chains/Ethereum/Data/uniswap_router_v2.json";
    auto abi = load_json_str(path);
    // https://etherscan.io/tx/0x57a2414f3cd9ca373b7e663ae67ecf933e40cb77a6e4ed28e4e28b5aa0d8ec63
    auto call = parse_hex(
        "0x38ed17390000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000"
        "00000000000000000000000000000000229f7e501ad62bdb000000000000000000000000000000000000000000"
        "00000000000000000000a00000000000000000000000007d8bf18c7ce84b3e175b339c4ca93aed1dd166f10000"
        "00000000000000000000000000000000000000000000000000005f0ed070000000000000000000000000000000"
        "00000000000000000000000000000000040000000000000000000000006b175474e89094c44da98b954eedeac4"
        "95271d0f0000000000000000000000009f8f72aa9304c8b593d555f12ef6589cc3a579a2000000000000000000"
        "000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000e41d2489571d32218924"
        "6dafa5ebde1f4699f498");
    auto decoded = decodeCall(call, abi);
    auto expected =
        R"|({"function":"swapExactTokensForTokens(uint256,uint256,address[],address,uint256)","inputs":[{"name":"amountIn","type":"uint256","value":"1000000000000000000"},{"name":"amountOutMin","type":"uint256","value":"2494851601099271131"},{"name":"path","type":"address[]","value":["0x6B175474E89094C44Da98b954EedeAC495271d0F","0x9f8F72aA9304c8B593d555F12eF6589cC3A579A2","0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2","0xE41d2489571d322189246DaFA5ebDe1F4699F498"]},{"name":"to","type":"address","value":"0x7d8bf18C7cE84b3E175b339c4Ca93aEd1dD166F1"},{"name":"deadline","type":"uint256","value":"1594806384"}]})|";

    EXPECT_EQ(decoded.value(), expected);
}

TEST(ContractCall, KyberTrade) {
    auto path = TESTS_ROOT + "/chains/Ethereum/Data/kyber_proxy.json";
    auto abi = load_json_str(path);

    // https://etherscan.io/tx/0x51ffab782b9a27d754389505d5a50db525c04c68142ce20512d579f10f9e13e4
    auto call = parse_hex(
        "ae591d54000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee000000000000000000"
        "000000000000000000000000000004a97d605a3b980000000000000000000000000000dac17f958d2ee523a220"
        "6206994597c13d831ec70000000000000000000000007755297c6a26d495739206181fe81646dbd0bf39ffffff"
        "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000000000000000000000000000"
        "000000000000000ce32ff7d63c35d189000000000000000000000000440bbd6a888a36de6e2f6a25f65bc4e168"
        "74faa9000000000000000000000000000000000000000000000000000000000000000800000000000000000000"
        "000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000"
        "000000000000000000");
    auto decoded = decodeCall(call, abi);

    auto expected =
        R"|({"function":"tradeWithHintAndFee(address,uint256,address,address,uint256,uint256,address,uint256,bytes)","inputs":[{"name":"src","type":"address","value":"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"},{"name":"srcAmount","type":"uint256","value":"86000000000000000000"},{"name":"dest","type":"address","value":"0xdAC17F958D2ee523a2206206994597C13D831ec7"},{"name":"destAddress","type":"address","value":"0x7755297C6A26D495739206181Fe81646dbD0Bf39"},{"name":"maxDestAmount","type":"uint256","value":"115792089237316195423570985008687907853269984665640564039457584007913129639935"},{"name":"minConversionRate","type":"uint256","value":"237731504554534883721"},{"name":"platformWallet","type":"address","value":"0x440bBd6a888a36DE6e2F6A25f65bc4e16874faa9"},{"name":"platformFeeBps","type":"uint256","value":"8"},{"name":"hint","type":"bytes","value":"0x"}]})|";

    EXPECT_EQ(decoded.value(), expected);
}

TEST(ContractCall, ApprovalForAll) {
    auto path = TESTS_ROOT + "/chains/Ethereum/Data/erc721.json";
    auto abi = load_json_str(path);

    // https://etherscan.io/tx/0xc2744000a107aee4761cf8a638657f91c3003a54e2f1818c37d781be7e48187a
    auto call = parse_hex("0xa22cb46500000000000000000000000088341d1a8f672d2780c8dc725902aae72f143b"
                          "0c0000000000000000000000000000000000000000000000000000000000000001");
    auto decoded = decodeCall(call, abi);

    auto expected =
        R"|({"function":"setApprovalForAll(address,bool)","inputs":[{"name":"to","type":"address","value":"0x88341d1a8F672D2780C8dC725902AAe72F143B0c"},{"name":"approved","type":"bool","value":true}]})|";

    EXPECT_EQ(decoded.value(), expected);
}

TEST(ContractCall, CustomCall) {
    auto path = TESTS_ROOT + "/chains/Ethereum/Data/custom.json";
    auto abi = load_json_str(path);

    auto call = parse_hex("ec37a4a000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006400000000000000000000000000000000000000000000000000000000000000067472757374790000000000000000000000000000000000000000000000000000");
    auto decoded = decodeCall(call, abi);
    auto expected =
        R"|({"function":"setName(string,uint256,int32)","inputs":[{"name":"name","type":"string","value":"trusty"},{"name":"age","type":"uint256","value":"3"},{"name":"height","type":"int32","value":"100"}]})|";

    EXPECT_EQ(decoded.value(), expected);
}

TEST(ContractCall, SetResolver) {
    auto call = parse_hex("0x1896f70ae71cd96d4ba1c4b512b0c5bee30d2b6becf61e574c32a17a67156fa9ed3c4c"
                          "6f0000000000000000000000004976fb03c32e5b8cfe2b6ccb31c09ba78ebaba41");
    auto path = TESTS_ROOT + "/chains/Ethereum/Data/ens.json";
    auto abi = load_json_str(path);
    auto decoded = decodeCall(call, abi);
    auto expected =
        R"|({"function":"setResolver(bytes32,address)","inputs":[{"name":"node","type":"bytes32","value":"0xe71cd96d4ba1c4b512b0c5bee30d2b6becf61e574c32a17a67156fa9ed3c4c6f"},{"name":"resolver","type":"address","value":"0x4976fb03C32e5B8cfe2b6cCB31c09Ba78EBaBa41"}]})|";

    EXPECT_EQ(decoded.value(), expected);
}

TEST(ContractCall, RenewENS) {
    auto call = parse_hex(
        "0xacf1a84100000000000000000000000000000000000000000000000000000000000000400000000000000000"
        "000000000000000000000000000000000000000001e18558000000000000000000000000000000000000000000"
        "000000000000000000000a68657769676f76656e7300000000000000000000000000000000000000000000");
    auto path = TESTS_ROOT + "/chains/Ethereum/Data/ens.json";
    auto abi = load_json_str(path);
    auto decoded = decodeCall(call, abi);
    auto expected =
        R"|({"function":"renew(string,uint256)","inputs":[{"name":"name","type":"string","value":"hewigovens"},{"name":"duration","type":"uint256","value":"31556952"}]})|";

    EXPECT_EQ(decoded.value(), expected);
}

TEST(ContractCall, Multicall) {
    auto call = parse_hex(
        "0xac9650d800000000000000000000000000000000000000000000000000000000000000200000000000000000"
        "000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000"
        "000000000000000000008000000000000000000000000000000000000000000000000000000000000001000000"
        "0000000000000000000000000000000000000000000000000000000001a0000000000000000000000000000000"
        "000000000000000000000000000000028000000000000000000000000000000000000000000000000000000000"
        "00000044d5fa2b00e71cd96d4ba1c4b512b0c5bee30d2b6becf61e574c32a17a67156fa9ed3c4c6f0000000000"
        "0000000000000047331175b23c2f067204b506ca1501c26731c990000000000000000000000000000000000000"
        "000000000000000000000000000000000000000000000000000000000000000000000000000000000064304e6a"
        "dee71cd96d4ba1c4b512b0c5bee30d2b6becf61e574c32a17a67156fa9ed3c4c6f000000000000000000000000"
        "000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000"
        "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
        "000000000000000000000000000000000000000000a48b95dd71e71cd96d4ba1c4b512b0c5bee30d2b6becf61e"
        "574c32a17a67156fa9ed3c4c6f000000000000000000000000000000000000000000000000000000000000003c"
        "000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000"
        "0000000000000000000000000000000000001447331175b23c2f067204b506ca1501c26731c990000000000000"
        "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
        "0000000000000000000000000000000000000000a48b95dd71e71cd96d4ba1c4b512b0c5bee30d2b6becf61e57"
        "4c32a17a67156fa9ed3c4c6f00000000000000000000000000000000000000000000000000000000000002ca00"
        "000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000"
        "000000000000000000000000000000000014d30f834b53d8f7e851e87b90ffa65757a35b850500000000000000"
        "000000000000000000000000000000000000000000000000000000000000000000");
    ASSERT_EQ(4 + 928ul, call.size());
    auto path = TESTS_ROOT + "/chains/Ethereum/Data/ens.json";
    auto abi = load_json_str(path);
    auto decoded = decodeCall(call, abi);
    auto expected =
        R"|({"function":"multicall(bytes[])","inputs":[{"name":"data","type":"bytes[]","value":["0xd5fa2b00e71cd96d4ba1c4b512b0c5bee30d2b6becf61e574c32a17a67156fa9ed3c4c6f00000000000000000000000047331175b23c2f067204b506ca1501c26731c990","0x304e6adee71cd96d4ba1c4b512b0c5bee30d2b6becf61e574c32a17a67156fa9ed3c4c6f00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000","0x8b95dd71e71cd96d4ba1c4b512b0c5bee30d2b6becf61e574c32a17a67156fa9ed3c4c6f000000000000000000000000000000000000000000000000000000000000003c0000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000001447331175b23c2f067204b506ca1501c26731c990000000000000000000000000","0x8b95dd71e71cd96d4ba1c4b512b0c5bee30d2b6becf61e574c32a17a67156fa9ed3c4c6f00000000000000000000000000000000000000000000000000000000000002ca00000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000014d30f834b53d8f7e851e87b90ffa65757a35b8505000000000000000000000000"]}]})|";

    EXPECT_EQ(decoded.value(), expected);
}

TEST(ContractCall, Invalid) {
    EXPECT_FALSE(decodeCall(Data(), "{}").has_value());
    EXPECT_FALSE(decodeCall(parse_hex("0xa22cb46500"), "{}").has_value());
}

TEST(ContractCall, GetAmountsOut) {
    auto call = parse_hex(
        "d06ca61f"
        "0000000000000000000000000000000000000000000000000000000000000064"
        "0000000000000000000000000000000000000000000000000000000000000040"
        "0000000000000000000000000000000000000000000000000000000000000001"
        "000000000000000000000000f784682c82526e245f50975190ef0fff4e4fc077");
    auto path = TESTS_ROOT + "/chains/Ethereum/Data/getAmountsOut.json";
    auto abi = load_json_str(path);

    auto decoded = decodeCall(call, abi);
    ASSERT_TRUE(decoded.has_value());
    auto expected =
        R"|({"function":"getAmountsOut(uint256,address[])","inputs":[{"name":"amountIn","type":"uint256","value":"100"},{"name":"path","type":"address[]","value":["0xF784682C82526e245F50975190EF0fff4E4fC077"]}]})|";
    EXPECT_EQ(decoded.value(), expected);
}

TEST(ContractCall, 1inch) {
    auto abiPath = TESTS_ROOT + "/chains/Ethereum/Data/1inch.json";
    auto decodedPath = TESTS_ROOT + "/chains/Ethereum/Data/1inch_decoded.json";

    auto abi = load_json_str(abiPath);
    auto expected = load_json(decodedPath);

    // https://etherscan.io/tx/0xc2d113151124579c21332d4cc6ab2b7f61e81d62392ed8596174513cb47e35ba
    auto call = parse_hex(
        "7c02520000000000000000000000000027239549dd40e1d60f5b80b0c4196923745b1fd2000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000001800000000000000000000000002b591e99afe9f32eaa6214f7b7629768c40eeb39000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000027239549dd40e1d60f5b80b0c4196923745b1fd20000000000000000000000001611c227725c5e420ef058275ae772b41775e261000000000000000000000000000000000000000000000000000005d0fadb1c0000000000000000000000000000000000000000000000000000000005c31df1da000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000022000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002080000000000000000000000069d91b94f0aaf8e8a2586909fa77a5c2c89818d50000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000104128acb080000000000000000000000001611c227725c5e420ef058275ae772b41775e2610000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000005d0fadb1c0000000000000000000000000000000000000000000000000000000001000276a400000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000400000000000000000000000002b591e99afe9f32eaa6214f7b7629768c40eeb39000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000000");
    auto decoded = decodeCall(call, abi);

    ASSERT_TRUE(decoded.has_value());
    nlohmann::json decodedJson = nlohmann::json::parse(decoded.value());
    EXPECT_EQ(decodedJson, expected);
}

TEST(ContractCall, TupleNested) {
    auto abiPath = TESTS_ROOT + "/chains/Ethereum/Data/tuple_nested.json";
    auto decodedPath = TESTS_ROOT + "/chains/Ethereum/Data/tuple_nested_decoded.json";
    auto abi = load_json_str(abiPath);
    auto expected = load_json(decodedPath);

    auto call = parse_hex(
        "74b6ef0b"
        "0000000000000000000000000000000000000000000000000000000000000001"
        "0000000000000000000000000000000000000000000000000000000000000002"
        "0000000000000000000000000000000000000000000000000000000000000003"
        "0000000000000000000000000000000000000000000000000000000000000004"
        "0000000000000000000000000000000000000000000000000000000000000005"
        "0000000000000000000000000000000000000000000000000000000000000001");
    auto decoded = decodeCall(call, abi);
    ASSERT_TRUE(decoded.has_value());
    nlohmann::json decodedJson = nlohmann::json::parse(decoded.value());
    EXPECT_EQ(decodedJson, expected);
}

TEST(ContractCall, TupleArray) {
    auto abiPath = TESTS_ROOT + "/chains/Ethereum/Data/swap_v2.json";
    auto decodedPath = TESTS_ROOT + "/chains/Ethereum/Data/swap_v2_decoded.json";
    auto abi = load_json_str(abiPath);
    auto expectedJson = load_json(decodedPath);

    auto call = parse_hex("846a1bc6000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec700000000000000000000000000000000000000000000000000470de4df82000000000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000740000000000000000000000000000000000000000000000000000000000000078000000000000000000000000000000000000000000000000000000000000007c00000000000000000000000000000000000000000000000000000000000000820000000000000000000000000a140f413c63fbda84e9008607e678258fffbc76b00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000001800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec7000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000044095ea7b300000000000000000000000099a58482bd75cbab83b27ec03ca68ff489b5788f00000000000000000000000000000000000000000000000000470de4df820000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000099a58482bd75cbab83b27ec03ca68ff489b5788f000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000046000000000000000000000000000000000000000000000000000000000000003840651cb35000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec7000000000000000000000000bebc44782c7db0a1a60cb6fe97d0b483032ff1c7000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000470de4df8200000000000000000000000000000000000000000000000000000000298ce42936ed0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ce16f69375520ab01377ce7b88f5ba8c48f8d66600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000045553444300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000762696e616e636500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002a307863653136463639333735353230616230313337376365374238386635424138433438463844363636000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000a140f413c63fbda84e9008607e678258fffbc76b000000000000000000000000000000000000000000000000000000000000000700000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000001e0000000000000000000000000000000000000000000000000000000000000036000000000000000000000000000000000000000000000000000000000000005a0000000000000000000000000000000000000000000000000000000000000072000000000000000000000000000000000000000000000000000000000000009600000000000000000000000000000000000000000000000000000000000000ac000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000004268b8f0b87b6eae5d897996e6b845ddbd99adf300000000000000000000000000000000000000000000000000000000000000010000000000000000000000004268b8f0b87b6eae5d897996e6b845ddbd99adf3000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000044095ea7b30000000000000000000000001b81d678ffb9c0263b24a97847620c99d213eb1400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000004268b8f0b87b6eae5d897996e6b845ddbd99adf3000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000010000000000000000000000001b81d678ffb9c0263b24a97847620c99d213eb14000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001e00000000000000000000000000000000000000000000000000000000000000104414bf3890000000000000000000000004268b8f0b87b6eae5d897996e6b845ddbd99adf300000000000000000000000055d398326f99059ff775485246999027b319795500000000000000000000000000000000000000000000000000000000000000640000000000000000000000004fd39c9e151e50580779bd04b1f7ecc310079fd300000000000000000000000000000000000000000000000000000189c04a7044000000000000000000000000000000000000000000000000000029a23529cf68000000000000000000000000000000000000000000005af4f3f913bd553d03b900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000004268b8f0b87b6eae5d897996e6b845ddbd99adf30000000000000000000000000000000000000000000000000000000000000005000000000000000000000000000000000000000000000000000000000000000100000000000000000000000055d398326f99059ff775485246999027b3197955000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000044095ea7b30000000000000000000000001b81d678ffb9c0263b24a97847620c99d213eb14000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000055d398326f99059ff775485246999027b3197955000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000010000000000000000000000001b81d678ffb9c0263b24a97847620c99d213eb14000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001e00000000000000000000000000000000000000000000000000000000000000104414bf38900000000000000000000000055d398326f99059ff775485246999027b3197955000000000000000000000000bb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c00000000000000000000000000000000000000000000000000000000000001f40000000000000000000000004fd39c9e151e50580779bd04b1f7ecc310079fd300000000000000000000000000000000000000000000000000000189c04a7045000000000000000000000000000000000000000000005b527785e694f805bdd300000000000000000000000000000000000000000000005f935a1fa5c4a6ec61000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000055d398326f99059ff775485246999027b319795500000000000000000000000000000000000000000000000000000000000000050000000000000000000000000000000000000000000000000000000000000001000000000000000000000000bb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000242e1a7d4d0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000bb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000a140f413c63fbda84e9008607e678258fffbc76b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
    auto decoded = decodeCall(call, abi);
    ASSERT_TRUE(decoded.has_value());

    nlohmann::json parsedJson = nlohmann::json::parse(decoded.value());
    EXPECT_EQ(parsedJson, expectedJson);
}

} // namespace TW::Ethereum::ABI::tests
